package com.zj.config;

import com.zj.util.DataCenterIdAssigner;
import com.zj.util.SnowFlakeIdGenrator;
import com.zj.util.WorkerIdAssigner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 雪花算法配置类
 */
@Configuration
public class SnowFlakeConfig {

    //数据中心id
    @Autowired
    private DataCenterIdAssigner dataCenterIdAssigner;
    //工作节点id
    @Autowired
    private WorkerIdAssigner workerIdAssigner;

    @Bean
    public SnowFlakeIdGenrator snowFlakeIdGenrator(){
        //获取数据中心id
        Long dataCenterId = dataCenterIdAssigner.getDataCenterId();
        //获取工作节点id
        Long workerId = workerIdAssigner.getWorkerId();
        return new SnowFlakeIdGenrator(dataCenterId,workerId);
    }
}
